﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ResearchRepository.Models;

namespace WebControlsTest
{
	// centralized set of global vars, used like a bank of #define's in C/C++
		// allows for single-change updates and spell-checking/Intellisense
	public static partial class GLOBALS
	{
		// server paths
		public const string repoDataRootDir = "C:\\RepoDataRoot\\";

		// db login credentials
		public const string dbConnStr = "Server=66.168.42.47;Username=repoClient;Password=This is a repo password.;Database=researchRepo;Allow Zero Datetime=true";
		//public const string dbConnStr = "Server=localhost;Username=repoClient;Password=This is a repo password.;Database=researchRepo;Allow Zero Datetime=true";

		// session variable names
			// NOTE: using vars to store session variable names makes the actual choice of name unimportant, while making it easy to ensure that each name is unique
		public const string userLoginSessionVar = "repoUser";
		public const string passLoginSessionVar = "repoPass";
		public const string userObjSessionVar = "repoUserObj";	// name of session var that holds user info;
																// repoUserObj is used as proof of authentication; repoUserObj = NULL if not logged in
		// misc
		public const string masterTitlePrefix = "ResearchRepository";
	}
	public partial class RRSiteMaster : System.Web.UI.MasterPage
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			// set account-related buttons to appropriate config
			RRUser u = (RRUser) Session[GLOBALS.userObjSessionVar];	// u != null --> signed in
			newProjectsButton.Visible = u != null;
			adminButton.Visible = u != null && RRDatabaseManager.userIsAdmin(u.UserID);
			if (u != null)
			{
				registerAccountButton.Text = u.FullName + " (" + u.UserName + ")";
				registerAccountButton.PostBackUrl = "Account.aspx";
				logInLogOutButton.Text = "Logout";
				logInLogOutButton.PostBackUrl = "Logout.aspx";
			}
			else
			{
				registerAccountButton.Text = "Register";
				registerAccountButton.PostBackUrl = "Register.aspx";
				logInLogOutButton.Text = "Login";
				logInLogOutButton.PostBackUrl = "Login.aspx";
			}
		}
	}
}